package cn.piesat.dao;

import cn.piesat.vo.userInfoConfig.ConfigInfoProjection;
import cn.piesat.dto.PiesatUserInfoConfigDTO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * 用户配置项信息持久层
 *
 * @author xhl
 */
public interface PiesatUserInfoConfigDAO extends JpaRepository<PiesatUserInfoConfigDTO,String> {

    /**
     * 查询所有用户配置项信息 按照创建时间正序
     * @return
     */
    List<PiesatUserInfoConfigDTO> findAllByOrderByCreateTime();

    /**
     * 根据条件查询是否为登录项表单集合
     * @param isLogin
     * @return
     */
    List<PiesatUserInfoConfigDTO> findAllByIsNotLoginOrderByCreateTime(Integer isLogin);

    /**
     * 根据条件查询是否为注册项表单集合
     * @param isRegister
     * @return
     */
    List<PiesatUserInfoConfigDTO> findAllByIsNotRegisterOrderByCreateTime(Integer isRegister);

    /**
     * 根据条件查询是否为搜索项表单集合
     * @param isSearch
     * @return
     */
    List<PiesatUserInfoConfigDTO> findAllByIsNotSearchOrderByCreateTime(Integer isSearch);

    @Query(nativeQuery = true, value = "select u.FIELD as field,u.FORM_TYPE as formType,c.USER_CONFIG_INFO as configInfo" +
            " from piesat_user_userinfo_config u" +
            " left join piesat_user_configinfo c on u.ID = c.USER_CONFIG_ID" +
            " where u.IS_NOT_REGISTER = :isRegister" +
            " and c.USER_INFO_ID = :userId")
    List<ConfigInfoProjection> findLeftConfigInfo(Integer isRegister, String userId);

}
